
export default class NativeClient {
	private static client: NativeClientIns;

	public static initClient(client: NativeClientIns){
		NativeClient.client = client;
	}

	public static sendMessage<A extends NCAPIStructure<any, any>>(api: string, data?: any, ccdata?: any): A{
		data = data ?? {}
		abd.$planet_log_poof$.$planet_tag_poof$([
			['NATIVE', 'tan'],
			['SEND', 'skyblue']
		].map(el=>el[0]+':'+el[1]).join(';'), api, '\n~~~~~~~~~~\nDATA:', data, '\n~~~~~~~~~~\n');

		let struct: A;
		if(this.client){
			struct = this.client.callStaticMethod(api, data, ccdata);
		}else{
			abd.$planet_log_poof$.$planet_tag_poof$('没有原生端服务: tomato');
		}

		struct.$planet_response_poof$.then(res=>{
			abd.$planet_log_poof$.$planet_tag_poof$([
				['NATIVE', 'tan'],
				['BACK', 'lime']
			].map(el=>el[0]+':'+el[1]).join(';'), api, '\n~~~~~~~~~~\nSTRUCT:', struct, '\nRESULT:', res, '\n~~~~~~~~~~\n');
		});

		return struct;
	}
}

export abstract class NativeClientIns {
	public abstract callStaticMethod(api: string, data: any, ccdata?: any): any;
}

/** 请求结构 */
export interface NCAPIStructure<Req, Res> {
	/** 请求接口标识符 */
	$planet_api_poof$: string;
	/** 请求数据 */
	$planet_request_poof$: Req;
	/** 响应数据 */
	$planet_response_poof$: Promise<Res>;
}
